(Music) Welcome to JavaScript Dom Objects. After watching this video, you will be able
to list related node types, show how to access doc elements, and explain object naming. The W3C DOM level 2 defines
12 different types of nodes, seven of which have direct
applicability in HTML documents. Node types that are not applicable
to HTML are omitted from the table. This table is of interest so
that when you view a DOM tree, you understand the meaning
of the numeric node types. Each node type is a named constant that
is also represented by an integer value. So, for example, an ELEMENT_NODE
type is represented by the integer 1, an ATTRIBUTE_NODE type is
represented by the integer 2, a TEXT_NODE type is represented by the integer 3, and a COMMENT_NODE is
represented by the integer 8. In the DOM tree, the node name for ELEMENT_NODE
type is the name of the element or tag. For example, if you are looking at
a DIV element, the node name is DIV. If the DIV element has an
attribute like id=div123, then the attribute name is “id” and the attribute
value is “div123”, which is the name-value pair. Another example: If a paragraph element is followed by some text, the text string has a node
name of hash- sign-text, and the node value is the text string itself. The table lists some of the DOM Level 2 node
object properties and corresponding data types. You see these properties when
you view a DOM tree for an HTML page in a browser’s developer
tools, like Chrome’s DevTools. How do you access the elements
on an HTML page with the DOM API? When the document is loaded, the browser creates arrays for forms,
images, anchors, links, applets, and embeds. It then places all the objects
of each type into these arrays. The arrays are indexed as they
occur in the source document. The first index of each array starts at zero. Each of the array types, such as forms[ ],
contains an array of elements with each index element[ ] being the fields or
buttons that occur in that form. You can reference the element named field1 in the figure by its relative position
as document.forms[0].elements[0] You can reference the same field
with named elements; for example, document.forms["form1"] .elements["field1"], or even the shortened document.form1.field1 Since only one document can
be contained in a window, shown by the dashed line in the figure,
you can leave out the window prefix. However, you cannot omit the document
prefix from the referenced object. The id attribute identifies
an element in a document. The id attribute of an element is used
by scripts to refer to the element with a name that matches the value of the id attribute. In order to assign a scriptable
reference name to an HTML element with the id attribute, use
the following conventions: The id must be a unique name in the document. The name must be in quotation marks
when assigned to the id attribute. The name must not start with a numeric digit. The function that is used to return a
node object that matches the id value is document.getElementById with the name
of the id as a parameter argument It is suggested that the same value is used for both the id and the name attribute
(seen earlier) when both are used In this video, you learned how to list the related node types, how to access nested objects using a dot notation, and how to name objects to make
accessing them from the script easier.